# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This will parse a textual representation of a duration. The formats
# accepted are based on the ISO-8601 duration format {@code PnDTnHnMn.nS}
# with days considered to be exactly 24 hours.
# <p>
# Examples:
# <pre>
#    "PT20.345S" -- parses as "20.345 seconds"
#    "PT15M"     -- parses as "15 minutes" (where a minute is 60 seconds)
#    "PT10H"     -- parses as "10 hours" (where an hour is 3600 seconds)
#    "P2D"       -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
#    "P2DT3H4M"  -- parses as "2 days, 3 hours and 4 minutes"
#    "P-6H3M"    -- parses as "-6 hours and +3 minutes"
#    "-P6H3M"    -- parses as "-6 hours and -3 minutes"
#    "-P-6H+3M"  -- parses as "+6 hours and -3 minutes"
# </pre>
filter: "{ tags -> tags.job_name == 'rabbitmq-monitoring' }" # The OpenTelemetry job name
expSuffix: tag({tags -> tags.cluster = 'rabbitmq::' + tags.cluster}).service(['cluster'], Layer.RABBITMQ)
metricPrefix: meter_rabbitmq
metricsRules:
  - name: memory_available_before_publisher_blocked
    exp: rabbitmq_resident_memory_limit_bytes.sum(['cluster', 'node']) - rabbitmq_process_resident_memory_bytes.sum(['cluster', 'node'])
  - name: disk_space_available_before_publisher_blocked
    exp: rabbitmq_disk_space_available_bytes.sum(['cluster', 'node'])
  - name: file_descriptors_available
    exp: rabbitmq_process_max_fds.sum(['cluster', 'node']) - rabbitmq_process_open_fds.sum(['cluster', 'node'])
  - name: tcp_socket_available
    exp: rabbitmq_process_max_tcp_sockets.sum(['cluster', 'node']) - rabbitmq_process_open_tcp_sockets.sum(['cluster', 'node'])

  - name: message_ready_delivered_consumers
    exp: rabbitmq_queue_messages_ready.sum(['cluster', 'node'])
  - name: message_unacknowledged_delivered_consumers
    exp: rabbitmq_queue_messages_unacked.sum(['cluster', 'node'])

  - name: messages_published
    exp: rabbitmq_global_messages_received_total.sum(['cluster', 'node']).rate('PT1M')
  - name: messages_confirmed
    exp: rabbitmq_global_messages_confirmed_total.sum(['cluster', 'node']).rate('PT1M')
  - name: messages_routed
    exp: rabbitmq_global_messages_routed_total.sum(['cluster', 'node']).rate('PT1M')
  - name: messages_unconfirmed
    exp: rabbitmq_global_messages_received_confirm_total.sum(['cluster', 'node']).rate('PT1M') - rabbitmq_global_messages_confirmed_total.sum(['cluster', 'node']).rate('PT1M')
  - name: messages_unroutable_dropped
    exp: rabbitmq_global_messages_unroutable_dropped_total.sum(['cluster', 'node']).rate('PT1M')
  - name: messages_unroutable_returned
    exp: rabbitmq_global_messages_unroutable_returned_total.sum(['cluster', 'node']).rate('PT1M')

  # queues
  - name: queues
    exp: rabbitmq_queues.sum(['cluster', 'node'])
  - name: queues_declared_total
    exp: rabbitmq_queues_declared_total.sum(['cluster', 'node']).rate('PT1M')
  - name: queues_created_total
    exp: rabbitmq_queues_created_total.sum(['cluster', 'node']).rate('PT1M')
  - name: queues_deleted_total
    exp: rabbitmq_queues_deleted_total.sum(['cluster', 'node']).rate('PT1M')

  # channels
  - name: channels
    exp: rabbitmq_channels.sum(['cluster', 'node'])
  - name: channels_opened_total
    exp: rabbitmq_channels_opened_total.sum(['cluster', 'node']).rate('PT1M')
  - name: channels_closed_total
    exp: rabbitmq_channels_closed_total.sum(['cluster', 'node']).rate('PT1M')

  # connections
  - name: connections
    exp: rabbitmq_connections.sum(['cluster', 'node'])
  - name: connections_opened_total
    exp: rabbitmq_connections_opened_total.sum(['cluster', 'node']).rate('PT1M')
  - name: connections_closed_total
    exp: rabbitmq_connections_closed_total.sum(['cluster', 'node']).rate('PT1M')